home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / rdsh_11.zoo / desktop.zoo / desktop.c next >
C/C++ Source or Header  |  1992-03-20  |  3KB  |  110 lines

  1. /*    DESKTOP.PRG Program           by W. Alan B. Evans,
  2.                        [wabe@ukc.ac.uk]  March 1992.
  3.  
  4.    If put in AUTO-FOLDER of "booting" RDY-ramdisk will ensure that any
  5. DESKTOP.INF file in the ramdisk's root directory will be copied to C:\
  6. (if C:\ exists) where the newer TOS-Versions will look for it.
  7.  
  8. */
  9.  
  10. #include <osbind.h>
  11.  
  12. extern    char *strcpy(),*gts();
  13.  
  14. main()
  15.  
  16. {    long st;    int drm;    char file[60];
  17.  
  18. /*   This is escape from "BOOT & WARMSTART" loop caused by faulty ACC's etc.
  19.      since it enables one to invoke a simple non-GEM shell e.g ME.TOS,
  20.      COMMAND.PRG, RDYSH.PRG or GULAM.PRG etc. to rename the offending ACC
  21.      or boot program
  22. */
  23.     if (Cconis()== -1 && (Crawcin() & 0x5f) == 'X') {
  24.     Cconws("\r\n  FULL PATH\\NAME OF PROGRAM TO BE EXECUTED: ");
  25.     Pexec(0,gts(file),"\0","\0");
  26.     }
  27.  
  28.     if (drm & 04)
  29.     if (Sversion() >= 0x1400)      /*  STE TOS Present!    */
  30. /*  Ensure the proper DESKTOP.INF file is looked at by new TOS  */
  31.     st= fc("DESKTOP.INF\0","C:\\DESKTOP.INF\0");
  32. /*  Execute the 40-Folder Patch Prog if found on C:\ with old TOS  */
  33.     else  Pexec(0,"C:\\FOLDR???.PRG\0","\0","\0");
  34.  
  35. Pterm(st);
  36. }
  37.  
  38.  
  39. /*
  40. *   A useful File_Copying subroutine - preserves date_stamp on old TOS  
  41. */
  42.  
  43. int fc(file1,file2)
  44. char *file1,*file2;
  45.  
  46. {    register char *buf;
  47.     int i,handle1,handle2,nsects,nsecmax,erc,no_tms,info[2];
  48.     long lo,nrw,flngth;
  49.  
  50.     erc= 0;    buf= 0;
  51.     if ((nsecmax = (int)(Malloc(-1L)/0x200L)-4) < 0)
  52.     { gemdos(9,"\r\n  INSUFFICIENT MEMORY!! ");  goto end;    }
  53.  
  54.     if ((handle1 = Fopen(file1,0)) < 0) return(0);
  55.     Fdatime(info,handle1,0);
  56.     flngth= Fseek(0L,handle1,2);
  57.     nsects= 1+(int)(flngth/0x200L);
  58.     if ((no_tms= nsects/nsecmax) == 0) nsecmax= nsects;
  59.  
  60.     if ((handle2 = Fopen(file2,0)) > 0)
  61.     { Fclose(handle2); Fdelete(file2);    }
  62.     if ((handle2 = Fcreate(file2,0)) < 0 )
  63.     { gemdos(9,"\r\n Fcreate FAILURE - COULD NOT OPEN FILE: ");
  64.     gemdos(9,file2);    --erc; goto end; }
  65.  
  66.     if ((buf= (char *)Malloc((long)nsecmax*0x200L+0x200L)) == 0)
  67.     { gemdos(9,"\r\n Malloc FAILURE!!! "); --erc; goto end; }
  68.     Cconws("\r  Copying "); Cconws(file1);
  69.     Cconws(" to "); Cconws(file2);  Cconws("\r\n ");
  70.     i=-1; while (i++ < no_tms)
  71.     { if (i == no_tms) nrw= flngth- (long)nsecmax*0x200L*i;
  72.     else  nrw= (long)nsecmax*0x200;
  73.  
  74.     { if ((lo= Fseek((long)nsecmax*0x200L*i,handle1,0) < 0) 
  75.     || (lo=Fread(handle1,nrw,buf)) != nrw)
  76.     { gemdos(9,"\r\n Fseek or Fread FAILURE");  --erc; goto end;    }
  77.     }
  78.  
  79.     { if ((lo= Fseek((long)(nsecmax*0x200L*i),handle2,0) < 0) 
  80.     || (lo= Fwrite(handle2,nrw,buf)) != nrw)
  81.     { gemdos(9,"\r\n Fseek or Fwrite FAILURE!  DISK FULL? "); --erc; goto end; }
  82.     }
  83.     }    /*  end of i loop  */
  84.  
  85. end:    if (!Fclose(handle2))
  86.     { if (erc < 0) Fdelete(file2); else
  87.     { handle2=Fopen(file2,0); Fdatime(info,handle2,1); Fclose(handle2); }
  88.     }
  89.     if (buf != 0) Mfree(buf);
  90. return(erc);
  91. }
  92.  
  93. /*
  94.         Cheap & minimal gets alternative
  95.     (  An economical alternative to "gets" - does not, however
  96.      respond to CNTRL-C on the Older TOSes    )
  97. */
  98.  
  99. #include <osbind.h>
  100.  
  101. char *gts(data)
  102. char *data;
  103.  
  104. {    register char *p = data;
  105.     while ((*p=gemdos(1)) != '\r')
  106.     if (*p == '\010') { --p; Cconws(" \010"); } else p++;
  107.     *p= '\0';
  108.     if (*data)    return(data);    else    return((char *)0);
  109. }
  110.